<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class repair_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	
	public function engineer_assign($insert)
	{
	
	$this->db->insert('repair',$insert);
	
	
	}
	
	public function delete_diagnosis($id)
	{
		$this->db->delete('diagnosis',array('service_id'=>$id));	
	
	}
	public function update_case_status($id,$eng_id)
	{
	$insert=array('status_id'=>5,'engineer_id'=>$eng_id,);
	$this->db->update('case',$insert,array('service_id'=>$id));
	
	}
	
	public function get_view()
	{
	$this->datatables
			->select("repair.id as id,case.case_no,repair.assigned_date,status.name,users.username,customer.customer_name,customer.mobile,customer.customer_address")
			->from('customer','repair','status','users','case')
             ->join('case','customer.service_id=case.service_id')			
            ->join('repair','case.id=repair.case_id')
            ->join('status','repair.status_id=status.id')	
            ->join('users'	,'repair.engineer_id=users.id')	
			->add_column("Actions",
			"<center>			</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_nonwarrantyview()
	{
	$this->datatables
			->select("nonwarranty_repair.id as id,nonwarranty_case.case_no,nonwarranty_repair.assigned_date,status_nonwarranty.name,users.username,customer.customer_name,customer.mobile,customer.customer_address")
			->from('customer','nonwarranty_repair','status_nonwarranty','users','nonwarranty_case')
             ->join('nonwarranty_case','customer.service_id=nonwarranty_case.service_id')			
            ->join('nonwarranty_repair','nonwarranty_case.id=nonwarranty_repair.case_id')
            ->join('status_nonwarranty','nonwarranty_repair.status_id=status_nonwarranty.id')	
            ->join('users'	,'nonwarranty_repair.engineer_id=users.id')	
			->add_column("Actions",
			"<center>			</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
public function get_view_completed()
	{
	$this->datatables
			->select("repair.id as id,case.case_no,repair.assigned_date,customer.customer_name,status.name,users.username,customer.mobile")
			->from('customer','repair','status','users','case')
             ->join('case','customer.service_id=case.service_id')			
            ->join('repair','case.id=repair.case_id')
            ->join('status','case.status_id=status.id')	
            ->join('users'	,'repair.engineer_id=users.id')	
			->where('repair.status_id',10)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/repair/view_report/$1'>
								<i class='icon-edit' title='Detail'></i>
								</a>
							    <a href='index.php/admin/repair/final_print/$1'>
								<i class='icon-print' title='Print'></i>
								</a>
								<a href='index.php/admin/repair/deliver_customer/$1'>
								<i class='icon-tasks' title='Delivered To Customer'></i>
								</a>
							
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function nonwarranty_completed()
	{
	$this->datatables
			->select("nonwarranty_repair.id as id,nonwarranty_case.case_no,nonwarranty_repair.assigned_date,customer.customer_name,status_nonwarranty.name,users.username,customer.mobile")
			->from('customer','nonwarranty_repair','status_nonwarranty','users','nonwarranty_case')
             ->join('nonwarranty_case','customer.service_id=nonwarranty_case.service_id')			
            ->join('nonwarranty_repair','nonwarranty_case.id=nonwarranty_repair.case_id')
            ->join('status_nonwarranty','nonwarranty_case.status_id=status_nonwarranty.id')	
            ->join('users'	,'nonwarranty_repair.engineer_id=users.id')	
			->where('nonwarranty_repair.status_id',11)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/repair/view_nonwarrantyreport/$1'>
								<i class='icon-edit'></i>
								</a>
								 <a href='index.php/admin/repair/final_print_nonwarranty/$1'>
								<i class='icon-print' title='Print'></i>
								</a>
								<a href='index.php/admin/repair/deliver_customer_nonwarranty/$1'>
								<i class='icon-tasks' title='Delivered To Customer'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}

public function get_view_pending()
	{
	$this->datatables
			->select("repair.id as id,case.case_no,repair.assigned_date,customer.customer_name,status.name,users.username,customer.mobile,customer.customer_address")
			->from('customer','repair','status','users','case')
             ->join('case','customer.service_id=case.service_id')			
            ->join('repair','case.id=repair.case_id')
            ->join('status','repair.status_id=status.id')	
            ->join('users'	,'repair.engineer_id=users.id')	
			->where('repair.status_id BETWEEN 8 AND 9')
			->add_column("Actions",
			"<center>			
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
	
public function get_customer($id)
{

$this->db->select('customer.id');
	$this->db->from('case', 'repair','customer' );
	$this->db->join('customer','customer.service_id=case.service_id');
	$this->db->join('repair', 'repair.case_id= case.id  '  );
	$this->db->where('repair.id',$id);
	$q = $this->db->get();
	return $q;
		
}
public function get_nonwarrantycustomer($id)
{

$this->db->select('customer.id');
	$this->db->from('nonwarranty_case', 'nonwarranty_repair','customer' );
	$this->db->join('customer','customer.service_id=nonwarranty_case.service_id');
	$this->db->join('nonwarranty_repair', 'nonwarranty_repair.case_id= nonwarranty_case.id  '  );
	$this->db->where('nonwarranty_repair.id',$id);
	$q = $this->db->get();
	return $q;
		
}
public function get_cus($id)
	{
	$query = $this->db->get_where('customer', array('id' => $id));
		return $query;
	}
public function get_case($id)
{
$this->db->select('case.case_no,case.id,repair.docket_no');
	$this->db->from('case', 'repair','customer' );
	$this->db->join('customer','customer.service_id=case.service_id');
	$this->db->join('repair', 'repair.case_id= case.id  '  );
	$this->db->where('customer.id',$id);
	$q = $this->db->get();
	return $q;
		
}
public function get_nonwarrantycase($id)
{
$this->db->select('nonwarranty_case.case_no,nonwarranty_case.id,nonwarranty_repair.order_no');
	$this->db->from('nonwarranty_case', 'nonwarranty_repair','customer' );
	$this->db->join('customer','customer.service_id=nonwarranty_case.service_id');
	$this->db->join('nonwarranty_repair', 'nonwarranty_repair.case_id= nonwarranty_case.id  '  );
	$this->db->where('customer.id',$id);
	$q = $this->db->get();
	return $q;
		
}
public function get_repair_detail($id)
{
$query = $this->db->get_where('repair', array('case_id' => $id));
		return $query;

}
public function nonwarranty_repair_detail($id)
{
$query = $this->db->get_where('nonwarranty_repair', array('case_id' => $id));
		return $query;

}
public function get_so($case_id)
{
$query = $this->db->get_where('so', array('case_id' => $case_id));
		return $query->result();
}	
public function get_part($case_id)
{

$this->db->select('received_order_part.id,received_order_part.name,received_order_part.serial,received_order_part.model,received_order_part.manufacturing_date,received_order_part.price');
	$this->db->from('received_order_part', 'received_order' );
	$this->db->join('received_order','received_order.id=received_order_part.received_order_id');
	$this->db->where('received_order.case_id',$case_id);
	$q = $this->db->get();
	return $q->result();
	
	
}	
		
public function get_image($id)
{

$query = $this->db->get_where('oldpart_img', array('so_id' => $id));
		return $query->result();
		
}
public function get_imagenew($id)
{

$query = $this->db->get_where('newpart_img', array('so_id' => $id));
		return $query->result();
		
}
public function get_reassigned_view()
	{
	$this->datatables
			->select("reassigned_caseid.id as id,reassigned_caseid.old_caseid,case.case_no,reassigned_caseid.date,customer.customer_name,customer.mobile,customer.customer_address")
			->from('customer','case','reassigned_caseid')
             ->join('case','customer.service_id=case.service_id')				
            ->join('reassigned_caseid','reassigned_caseid.new_caseid=case.id')	
			->add_column("Actions",
			"<center>			<a href='index.php/admin/reassigned_case/reassigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								<a href='index.php/admin/reassigned_case/delete_reassigned/$1'>
								<i class='icon-trash'></i>
								</a>
								
							    </center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
public function get_views($id)
	{
	$this->datatables
			->select("customer.id as id, case.case_no,repair.assigned_date,repair.expected_date,status.name,repair.docket_no,customer.customer_name,customer.mobile")
			->from('repair','customer','users','status','case')
			->join('case','repair.case_id=case.id')
			->join('customer','case.service_id=customer.service_id')
			->join('users','users.id=repair.engineer_id')
			->join('status','repair.status_id=status.id')
		    ->where('repair.status_id',5)
			->where('users.id',$id)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/repair/view_detail/$1'>
								<i class='icon-edit'></i>
								</a
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
	
public function get_view_nonwarranty($id)
	{
	$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_repair.order_no,nonwarranty_repair.assigned_date,nonwarranty_repair.expected_date,status_nonwarranty.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_repair','customer','users','status_nonwarranty','nonwarranty_case')
			->join('nonwarranty_case','nonwarranty_repair.case_id=nonwarranty_case.id')
			->join('customer','nonwarranty_case.service_id=customer.service_id')
			->join('users','users.id=nonwarranty_repair.engineer_id')
			->join('status_nonwarranty','nonwarranty_repair.status_id=status_nonwarranty.id')
		    ->where('nonwarranty_repair.status_id',6)
			->where('users.id',$id)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/repair/view_detail_nonwarranty/$1'>
								<i class='icon-edit'></i>
								</a
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}	
	
public function get_current_view($id)
	{
$this->datatables
			->select("customer.id as id, case.case_no,repair.assigned_date,repair.expected_date,status.name,repair.docket_no,customer.customer_name,customer.mobile")
			->from('repair','customer','users','status','case')
			->join('case','repair.case_id=case.id')
			->join('customer','case.service_id=customer.service_id')
			->join('users','users.id=repair.engineer_id')
			->join('status','repair.status_id=status.id')
			->where('case.status_id != 22')
			->where('users.id',$id)
		    ->where( 'repair.status_id BETWEEN 6 AND 9') 
		   
			
		    ->add_column("Actions",
			"<center>		<a href='index.php/engineer/repair/part_verification/$1'>
								<i class='icon-tags '></i>
								</a>
								
								</center>", "id")
			
			;
			
	   return  $this->datatables->generate();
	}
	public function get_currentnonwarranty_view($id)
	{
$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_repair.order_no,nonwarranty_repair.assigned_date,nonwarranty_repair.expected_date,status_nonwarranty.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_repair','customer','users','status_nonwarranty','nonwarranty_case')
			->join('nonwarranty_case','nonwarranty_repair.case_id=nonwarranty_case.id')
			->join('customer','nonwarranty_case.service_id=customer.service_id')
			->join('users','users.id=nonwarranty_repair.engineer_id')
			->join('status_nonwarranty','nonwarranty_repair.status_id=status_nonwarranty.id')
			->where('users.id',$id)
		    ->where( 'nonwarranty_repair.status_id BETWEEN 7 AND 10') 
		   
			
		    ->add_column("Actions",
			"<center>		<a href='index.php/engineer/repair/nonwarranty_part_verification/$1'>
								<i class='icon-tags '></i>
								</a>
								
								
								
								</center>", "id")
			
			;
			
	   return  $this->datatables->generate();
	}
		
public function get_all_view($id)
	{
$this->datatables
			->select("customer.id as id, case.case_no,repair.assigned_date,repair.completion_date,status.name,repair.docket_no,customer.customer_name,customer.mobile")
			->from('repair','customer','users','status','case')
			->join('case','repair.case_id=case.id')
			->join('customer','case.service_id=customer.service_id')
			->join('users','users.id=repair.engineer_id')
			->join('status','repair.status_id=status.id')
			->where('users.id',$id)
		    ->where( 'repair.status_id', 10) 
		   
			
		    ->add_column("Actions",
			"<center>		<a href='index.php/engineer/repair/view_detail_completed/$1'>
								<i class='icon-tags'></i>
								</a>
								
								
								
								</center>", "id")
			
			;
			
	   return  $this->datatables->generate();
	}
	public function nonwarranty_getall($id)
	{
$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_repair.assigned_date,nonwarranty_repair.completion_date,status_nonwarranty.name,nonwarranty_repair.order_no,customer.customer_name,customer.mobile")
			->from('nonwarranty_repair','customer','users','status_nonwarranty','nonwarranty_case')
			->join('nonwarranty_case','nonwarranty_repair.case_id=nonwarranty_case.id')
			->join('customer','nonwarranty_case.service_id=customer.service_id')
			->join('users','users.id=nonwarranty_repair.engineer_id')
			->join('status_nonwarranty','nonwarranty_repair.status_id=status_nonwarranty.id')
			->where('users.id',$id)
		    ->where( 'nonwarranty_repair.status_id', 11) 
		   
			
		    ->add_column("Actions",
			"<center>		<a href='index.php/engineer/repair/nonwarranty_completed/$1'>
								<i class='icon-tags'></i>
								</a>
								
								
								
								</center>", "id")
			
			;
			
	   return  $this->datatables->generate();
	}	
	
public function get_expense_detail($case_id)
{
$query = $this->db->get_where('engineer_expenses', array('case_id' => $case_id));
return $query;
}  	
public function company_profile()
{
return $this->db->get('company_profile');
}	
 public function get_casedetail($id)
	{
	$this->db->select('customer.*,country.name');
	$this->db->from('customer', 'case','repair' );
	$this->db->join('case', 'customer.service_id= case.service_id'  );
	$this->db->join('country', 'customer.country_purchase= country.id'  );
	$this->db->join('repair','repair.case_id=case.id');
	$this->db->where('case.status_id != 22');
	$this->db->where('repair.id',$id);
	$q = $this->db->get();
  return $q;
	}
 public function get_non_casedetail($id)
	{
	$this->db->select('customer.*,country.name');
	$this->db->from('customer', 'nonwarranty_case','nonwarranty_repair' );
	$this->db->join('nonwarranty_case', 'customer.service_id= nonwarranty_case.service_id'  );
	$this->db->join('country', 'customer.country_purchase= country.id'  );
	$this->db->join('nonwarranty_repair','nonwarranty_repair.case_id=nonwarranty_case.id');
	$this->db->where('nonwarranty_repair.id',$id);
	$q = $this->db->get();
  return $q;
	}
public function get_case_no($id)
{
$this->db->select('case.case_no,case.hp_case,case.id,case.service_id,country.name');
	$this->db->from('case', 'repair','country','customer' );
	$this->db->join('repair', 'repair.case_id= case.id'  );
	$this->db->join('customer', 'customer.service_id= case.service_id'  );
	$this->db->join('country', 'customer.country_purchase= country.id'  );
	$this->db->where('case.status_id != 22');
	$this->db->where('repair.id',$id);
	$q = $this->db->get();
  return $q;
}
public function get_nonwarrantycase_no($id)
{
$this->db->select('nonwarranty_case.case_no,nonwarranty_case.id,nonwarranty_case.service_id,country.name');
	$this->db->from('nonwarranty_case', 'nonwarranty_repair','country','customer' );
	$this->db->join('nonwarranty_repair', 'nonwarranty_repair.case_id= nonwarranty_case.id'  );
	$this->db->join('customer', 'customer.service_id= nonwarranty_case.service_id'  );
	$this->db->join('country', 'customer.country_purchase= country.id'  );
	$this->db->where('nonwarranty_repair.id',$id);
	$q = $this->db->get();
  return $q;
}
public function get_so_detail($id)
{
$this->db->select('so.name,so.code,so.so_no,so.case_id');
	$this->db->from('so');
	//$this->db->join('case','case.id=so.case_id');
	//$this->db->where('case.status_id != 22');
	$this->db->where('so.case_id',$id);
	$q = $this->db->get();
  return $q->result();
}
public function get_part_detail($id)
{
$this->db->select('received_order_part.name as name,received_order_part.model as code,received_order_part.serial as so_no');
	$this->db->from('received_order_part','received_order');
	$this->db->join('received_order','received_order.id=received_order_part.received_order_id');
	//$this->db->where('case.status_id != 22');
	$this->db->where('received_order.case_id',$id);
	$q = $this->db->get();
  return $q->result();
}
public function get_accesoriesdetail($id)
	{
	$query = $this->db->get_where('customer_accesories', array('customer_id' => $id));
		return $query->result();
	}

public function get_already_scan($id)
{
$query = $this->db->get_where('scan_receipt', array('case_id' => $id));
		return $query;

}
public function get_already_scan_nonwarranty($id)
{
$query = $this->db->get_where('scan_receipt_nonwarranty', array('case_id' => $id));
		return $query;

}

	
}
?>